import React, { useState } from 'react'
import { Row, Col, Radio, InputNumber, Slider, Button, Checkbox, Popover, Input, Space, Dropdown, Tag, Tooltip } from 'antd'
import EditLink from '@/components/EditLink';
import UploadImage from '@/components/UploadImage';
import { backgroundObj } from '@/utils/utils';
import SelectRadioModel from '@/components/SelectRadioModel'
import { SketchPicker } from 'react-color';
import { CloseOutlined } from '@ant-design/icons'
import './index.less'
const Navigation = (props) => {
    const { selectData, data, edit } = props
    const { selectIndex } = data
    const { radiusType, title, iconColor, searchColor, position, marginType, top, bottom, backgroundType, borderRadius, backgroundColor, backgroundImage, fontColor, paddingTop, paddingLeft } = selectData
    const [visible, setVisible] = useState(false)
    const [editVisible, setEditVisible] = useState(false)
    const [shopEdit, setShopEdit] = useState(false)
    const [bgVisible, setBgVisible] = useState(false)
    const navigationListProps = {
        title: "",
        src: "",
        linkType: "",
        linkData: {},
        linkSrc: '',
        showIphone: false
    }
    const renderTag = (item) => {
        const { linkType, linkSrc, linkData } = item
        if (linkType === 'customize') {
            return '链接|' + linkSrc
        } else {
            const { goodsName } = linkData
            return '商品|' + goodsName
        }
    }
    const items = (index, item) => {
        return [
            {
                label: (
                    <Button onClick={() => {
                        setShopEdit({
                            show: true,
                            details: [],
                            index: index
                        })
                    }} type='link'>商品</Button>
                ),
                key: '0',
            },
            {
                label: (
                    <Button onClick={() => {
                        setEditVisible({
                            show: true,
                            detail: item,
                            index: index
                        })
                    }} type='link'>自定义链接</Button>
                ),
                key: '1',
            },
        ]
    };
    const handleUpdate = (o) => {
        edit({
            list: data.list.map((val, index) => {
                if (index === selectIndex) {
                    return {
                        ...val,
                        ...o
                    }
                }
                return val
            })
        })
    }
    return <Row gutter={[12, 24]}>
        <Col className='editor-content-item-label'
            span={24}>
            内容
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            搜索功能仅限于课程搜索，例如：图文、直播、专栏等
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            <Space>
                <div>提示文字</div>
                <Input
                    showCount
                    maxLength={20}
                    onChange={(e) => {
                        handleUpdate({ title: e.target.value })
                    }} value={title}></Input>
            </Space>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            内容样式
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            边角样式:
            <Radio.Group onChange={(e) => {
                handleUpdate({
                    radiusType: e.target.value
                })
            }} value={radiusType}>
                <Radio value={'rightAngle'}>直角</Radio>
                <Radio value={'roundedCorners'}>圆角</Radio>
            </Radio.Group>
        </Col>
        {radiusType === 'roundedCorners' && <Col
            span={24}>
            <Row gutter={[12, 12]}>
                <Col span={6}>圆角半径</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={16}
                        onChange={(e) => handleUpdate({ borderRadius: e })}
                        value={borderRadius}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={16} onChange={(e) => {
                        handleUpdate({ borderRadius: e })
                    }} value={borderRadius}></InputNumber></Col>
            </Row>
        </Col>}
        <Col className='editor-content-item-label'
            span={24}>
            图文位置:
            <Radio.Group onChange={(e) => {
                handleUpdate({
                    position: e.target.value
                })
            }} value={position}>
                <Radio value={'flex-start'}>居左</Radio>
                <Radio value={'center'}>居中</Radio>
                <Radio value={'space-between'}>两端</Radio>
            </Radio.Group>
        </Col>
        <Col span={24}>
            <Space>
                <div className='editor-content-item-label'>文本颜色</div>
                <Button onClick={() => {
                    handleUpdate({ fontColor: '#B2B2B2' })
                }} type='link'>重置</Button>
                <Popover content={<SketchPicker
                    color={fontColor}
                    onChange={(e) => {
                        handleUpdate({ fontColor: e.hex })

                    }}></SketchPicker>} trigger={['click']} placement={'bottom'}>
                    <div className='design-color-set'>

                        <div style={{ background: fontColor }} className='design-color-block '></div>
                    </div>
                </Popover>
            </Space>
        </Col>
        <Col span={24}>
            <Space>
                <div className='editor-content-item-label'>图标颜色</div>
                <Button onClick={() => {
                    handleUpdate({ iconColor: '#B2B2B2' })
                }} type='link'>重置</Button>
                <Popover content={<SketchPicker
                    color={iconColor}
                    onChange={(e) => {
                        handleUpdate({ iconColor: e.hex })

                    }}></SketchPicker>} trigger={['click']} placement={'bottom'}>
                    <div className='design-color-set'>

                        <div style={{ background: iconColor }} className='design-color-block '></div>
                    </div>
                </Popover>
            </Space>
        </Col>
        <Col span={24}>
            <Space>
                <div className='editor-content-item-label'>搜索框颜色</div>
                <Button onClick={() => {
                    handleUpdate({ searchColor: '#f5f5f5' })
                }} type='link'>重置</Button>
                <Popover content={<SketchPicker
                    color={searchColor}
                    onChange={(e) => {
                        handleUpdate({ searchColor: e.hex })
                    }}></SketchPicker>} trigger={['click']} placement={'bottom'}>
                    <div className='design-color-set'>
                        <div style={{ background: searchColor }} className='design-color-block '></div>
                    </div>
                </Popover>
            </Space>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            组件样式
        </Col>
        <Col
            span={24}>
            <Row gutter={[12, 12]}>
                <Col span={6}>左右内边距</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={32}
                        onChange={(e) => handleUpdate({ paddingLeft: e })}
                        value={paddingLeft}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={32} onChange={(e) => {
                        handleUpdate({ paddingLeft: e })
                    }} value={paddingLeft}></InputNumber></Col>
            </Row>
        </Col>
        <Col
            span={24}>
            <Row gutter={[12, 12]}>
                <Col span={6}>上下内边距</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={32}
                        onChange={(e) => handleUpdate({ paddingTop: e })}
                        value={paddingTop}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={32} onChange={(e) => {
                        handleUpdate({ paddingTop: e })
                    }} value={paddingTop}></InputNumber></Col>
            </Row>
        </Col>
        <Col className='editor-content-item-label'
            span={24}>
            外边距：
            <Radio.Group onChange={(e) => {
                handleUpdate({
                    top: 12,
                    bottom: 0,
                    marginType: e.target.value
                })
            }} value={marginType}>
                <Radio value={'detault'}>默认</Radio>
                <Radio value={'customize'}>自定义</Radio>
            </Radio.Group>
        </Col>
        {marginType === 'customize' && <Col
            span={24}>
            <Row gutter={[12, 12]}>
                <Col span={6}>上</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={32}
                        onChange={(e) => handleUpdate({ top: e })}
                        value={top}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={32} onChange={(e) => {
                        handleUpdate({ top: e })
                    }} value={top}></InputNumber></Col>
            </Row>
            <Row gutter={[12, 12]}>
                <Col span={6}>下</Col>
                <Col span={12}>
                    <Slider
                        min={0}
                        max={32}
                        onChange={(e) => handleUpdate({ bottom: e })}
                        value={bottom}
                    />
                </Col>
                <Col span={6}><InputNumber min={0}
                    max={32} onChange={(e) => {
                        handleUpdate({ bottom: e })
                    }} value={bottom}></InputNumber></Col>
            </Row>
        </Col>}
        <Col className='editor-content-item-label'
            span={24}>
            导航背景
        </Col>
        <Col span={24}>
            <Radio.Group onChange={(e) => {
                handleUpdate({ backgroundType: e.target.value, backgroundColor:"#ffffff",backgroundImage: '' })
            }} value={backgroundType}>
                <Radio value={'default'}>默认</Radio>
                <Radio value={'color'}>颜色</Radio>
                <Radio value={'image'}>图片</Radio>
            </Radio.Group>
        </Col>
        {backgroundType === 'color' ? <Col span={24}>
            <div className='editor-set-color'>
                <div className='design-editor-content-item-label'>
                    自定义颜色
                </div>
                <div className='design-editor-link'>
                    <Space>
                        {/* <SketchPicker color={backgroundColor}
                            onChangeComplete={(e) => {
                                edit({
                                    backgroundColor: e
                                })

                            }}></SketchPicker> */}
                        <Button type='link'>重置</Button>
                        <Popover content={<SketchPicker
                            color={backgroundColor}
                            onChange={(e) => {
                                handleUpdate({
                                    backgroundColor: e.hex
                                })

                            }}></SketchPicker>} trigger={['click']} placement={'bottom'}>
                            <div className='design-color-set'>
                                <div style={{ background: backgroundColor }} className='design-color-block '></div>
                            </div>
                        </Popover>

                    </Space>
                </div>
            </div>
        </Col> : backgroundType === 'image' ? <Col span={24}>
            <div className='editor-set-color' onClick={(e) => {
                setBgVisible({
                    show: true,
                })
            }}>
                {backgroundImage ? <div style={backgroundObj(backgroundImage)} className='editor-set-uploadBlock'>
                </div> : <div className='editor-set-uploadBlock'>
                    <div className='editor-set-upload'>
                        <i className='icon-jia'></i>
                    </div>
                </div>}
            </div>
        </Col> : ""}
        <UploadImage handleImage={(e) => {
            if (e) {
                const { src } = e
                const { type, index } = visible
                if (type === 'edit') {
                    handleUpdate({
                        list: list.map((item, o) => {
                            if (index === o) {
                                return {
                                    ...item,
                                    src
                                }
                            }
                            else {
                                return item
                            }
                        })
                    })
                } else {
                    handleUpdate({
                        list: [...list, {
                            ...navigationListProps,
                            src
                        }]
                    })
                }

            }
        }} visible={visible} onClose={() => { setVisible(false) }}></UploadImage>
        <UploadImage handleImage={(e) => {
            if (e) {
                const { src } = e

                handleUpdate({
                    backgroundImage: src
                })
            }
        }} visible={bgVisible} onClose={() => { setBgVisible(false) }}></UploadImage>
        <EditLink handleCallback={(e) => {
            const { index } = editVisible
            handleUpdate({
                list: list.map((item, o) => {
                    if (index === o) {
                        return {
                            ...item,
                            linkType: 'customize',
                            ...e
                        }
                    }
                    else {
                        return item
                    }
                })
            })
        }} visible={editVisible} onClose={() => { setEditVisible(false) }}></EditLink>
        <SelectRadioModel onOk={(e) => {
            if (e[0]) {
                const { index } = shopEdit
                handleUpdate({
                    list: list.map((item, o) => {
                        if (index === o) {
                            return {
                                ...item,
                                linkType: 'shop',
                                linkData: e[0]
                            }
                        }
                        else {
                            return item
                        }
                    })
                })
            }

        }} visible={shopEdit} onClose={() => setShopEdit(false)}></SelectRadioModel>
    </Row>
}
export default Navigation
